import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getUserInfo } from '@/api/user'

export const useStore = defineStore(
  'big-user',
  () => {
    const token = ref('')
    //用户信息
    const user=ref({})
    const getUser=async()=>{
    const res=await getUserInfo()
    user.value=res.data.data
    console.log('用户信息',user.value)
    }

    const setToken = (newToken) => {
      token.value = newToken
      console.log('token保存为了', token.value)
    }
    const removeToken = () => {
      token.value = ''
    }
    const setUser=(newUser)=>{
      user.value=newUser
    }
    const removeUser=()=>{
      user.value={}
    }
    return { token, setToken, removeToken,user,getUser,setUser,removeUser}
  },
  {
    persist: true // 开启数据持久化
  }
)
